<script type="text/javascript" src="/kkpager/kkpager.js"></script>
<script type="text/javascript" src="/js/adm/vb-kkpager.js"></script>
<h1 class="page_title">VB课程班级管理</h1>
<span class="btn-upload form-group">
        <input class="input-text" type="text" id="keyword"
               <#if keyword??>
                   value="${keyword!''}"
               </#if>
               style="width:200px" placeholder="15信管">
        <a href="javascript:research('/adm/class/', '班级管理');" class="btn btn-primary upload-btn"><i
                    class="Hui-iconfont">&#xe665;</i> 搜 索</a>
    </span>
<input class="btn btn-primary radius" type="button" value="添 加"
       style="float: right;margin-bottom: 15px;" id="addClassBtn">
<#if pageBean.content?size != 0>
<table class="table table-border table-bordered table-hover"
<thead>
<tr>
    <th>班级名称</th>
    <th>班级人数</th>
    <th style="width: 25%">操 作</th>
</tr>
</thead>
<tbody>
<#list pageBean.content as bean>
    <tr>
        <td><input class="input-text" id="class${bean.classId}" readonly="readonly" disabled
                   value="${bean.classNum}"></td>
        <td>${bean.stuCount}人</td>
        <td>
            <input class="btn btn-secondary radius" type="button" value="班级详情"
                   onclick="selectClass(${bean.classId})">
            <input class="btn btn-warning radius" type="button" value="名称修改"
                   onclick="editClass(${bean.classId}, this)">
<#--            <input class="btn btn-danger radius" type="button" value="删 除" onclick="deleteClass(${bean.classId})">-->
        </td>
    </tr>
</#list>
<tr>
    <td colspan="4">
        <div id="kkpager"></div>
    </td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<#else>
    <div class="text-c" style="height: 300px;"><h3>无记录.</h3></div>
</#if>
<script type="text/javascript">
    var changeView = function(n) {
        selectView("/adm/class/?pageNum=" + n + "&keyword=" + "${keyword!''}", "班级详情");
    };
    $('#addClassBtn').on('click', function () {
        selectView("/adm/class/add", "添加班级信息");
    });
    var selectClass = function (id) {
        selectView("/adm/class/" + id, "班级详情");
    };

    var editClass = function (id, btn) {
        var editInput = $("#class" + id);
        editInput.removeAttr("readonly");
        editInput.removeAttr("disabled");
        $(btn).val("确 定");
        $(btn).attr("onclick", "confirmEdit(" + id + ", this)");
    };
    var confirmEdit = function (id, btn) {
        var editInput = $("#class" + id);
        if ('' === editInput.val().trim()) {
            alert("班级名称不能为空");
            return;
        }
        stupidAjaxGetJson(
            '/adm/class/' + id,
            "PUT",
            {className: editInput.val()},
            function (data) {
                if (!data.success) {
                    alert(data.msg);
                } else {
                    alert(data.msg);
                    editInput.attr("readonly", "readonly");
                    editInput.attr("disabled", "disabled");
                    $(btn).val("名称修改");
                    $(btn).attr("onclick", "editClass(" + id + ", this)");
                }
            }
        );
    };
</script>
<script type="text/javascript">
    generateKK(${pageBean.pageNum}, ${pageBean.pageCount}, ${pageBean.rowCount});
</script>